package com.yyq.thread;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author yyq
 * @create 2021-08-03 12:17
 */
public class ThreadPoll {
    public static void main(String[] args) {
        //1 提供指定线程数量的线程池
        ExecutorService service = Executors.newFixedThreadPool(10);
        //2 执行指定的线程操作，需要提供实现 Runable接口或者 Callable接口的对象
        service.execute(new NumberThread());//适合使用于Runnable
        service.execute(new Chinese());
        //service.submit();  //适合使用于Callable
        service.shutdown();//关闭线程池
    }
}
class Chinese implements java.lang.Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"yyq");
        }
    }
}

class NumberThread implements java.lang.Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+"  "+i);
        }
    }
}
